package com.stars.empoly.adapter

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.google.gson.Gson
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.R
import com.stars.empoly.activity.*
import com.stars.empoly.config.MIntentAction
import com.stars.empoly.databinding.ItemAddressListBinding
import com.stars.empoly.databinding.ItemMsgBinding
import com.stars.empoly.model.AddressList
import com.stars.empoly.model.MsgList
import com.stars.empoly.model.TrMsgList
import com.stars.empoly.vmodel.AddressListVModel
import com.stars.empoly.vmodel.MsgVModel
import com.trailer.base.base.BAdapter
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

class AddressListAdapter(var vm: AddressListVModel) : BAdapter<AddressList, BaseDataBindingHolder<ItemAddressListBinding>>(R.layout.item_address_list) {

    override fun convert(holder: BaseDataBindingHolder<ItemAddressListBinding>, item: AddressList) {
        holder.dataBinding?.vm = vm
        holder.dataBinding?.item = item
        holder.dataBinding?.position = holder.adapterPosition

        holder.dataBinding?.imgEdit?.onClick {
            UiSwitch.bundleRes(context() as Activity,
                AddressActivity::class.java,
                B().putString("bean", Gson().toJson(item)).ok(),
                MIntentAction.REQUEST_CODE_TWO)
        }

        holder.dataBinding?.ll?.onClick {
            if(vm.type=="1"){
                val intent = Intent()
                var bundle= Bundle()
                bundle.putString("bean",Gson().toJson(item))
                intent.putExtras(bundle)
                var con=context() as Activity
                con.setResult(Activity.RESULT_OK, intent)
                con.finish()
            }else{
                UiSwitch.bundleRes(context() as Activity,
                    AddressActivity::class.java,
                    B().putString("bean", Gson().toJson(item)).ok(),
                    MIntentAction.REQUEST_CODE_TWO)
            }

        }


    }
}
